package com.bytetool.server.controller;

import com.bytetool.server.entity.PerformanceInfo;
import com.bytetool.server.entity.PerformanceRequest;
import com.bytetool.server.service.IPerformanceInfoService;
import com.xweb.common.web.parameter.resolver.FormBody;
import com.xweb.common.web.response.RespPageResult;
import com.xweb.common.web.response.RespResult;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zouhuixing
 * @date 2024/3/31
 */
@RestController
@AllArgsConstructor
@RequestMapping("logs")
public class LoggerController {

    private IPerformanceInfoService performanceInfoService;

    @PostMapping
    public RespResult<String> addLogs(@RequestBody PerformanceInfo performanceInfo) {
        performanceInfoService.save(performanceInfo);
        return RespResult.builder().data("").build();
    }

    @GetMapping
    public RespPageResult listLogs(@FormBody PerformanceRequest performanceRequest) {
        return RespPageResult.builder().data(performanceInfoService.listMethodCallStackInfo(performanceRequest)).build();
    }
}
